<template>
  <div>
    <a-table
      style="height: 40vh;overflow: scroll;"
      ref="table"
      size="middle"
      bordered
      rowKey="id"
      :scroll="{x:true}"
      :columns="columns"
      :dataSource="dataSource"
      :pagination="false"
      :loading="loading"
      :rowClassName="tableRowClass"
      @change="handleTableChange">

      <template slot="htmlSlot" slot-scope="text">
        <div v-html="text"></div>
      </template>
      <template slot="imgSlot" slot-scope="text,record">
        <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
        <img
          v-else
          :src="getImgView(text)"
          :preview="record.id"
          height="25px"
          alt=""
          style="max-width:80px;font-size: 12px;font-style: italic;" />
      </template>
      <template slot="fileSlot" slot-scope="text">
        <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
        <a-button
          v-else
          :ghost="true"
          type="primary"
          icon="download"
          size="small"
          @click="downloadFile(text)">
          下载
        </a-button>
      </template>

      <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">编辑</a>
          <a-divider type="vertical" />
          <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
            <a>删除</a>
          </a-popconfirm>
        </span>

    </a-table>
  </div>
</template>

<script>

import { JeecgListMixin } from '@/mixins/JeecgListMixin'

export default {
  name: 'MesStatusWordValueList',
  mixins: [JeecgListMixin],
  components: {},
  props: {
    mainId: {
      type: String,
      default: '',
      required: false
    }
  },
  watch: {
    mainId: {
      immediate: true,
      handler(val) {
        if (!this.mainId) {
          this.clearList()
        } else {
          this.queryParam['historyId'] = val
          this.loadData(1)
        }
      }
    }
  },
  data() {
    return {
      description: '产品生产历史管理页面',
      disableMixinCreated: true,
      // 表头
      columns: [
        {
          title: '序号',
          align: 'center',
          dataIndex: 'bitpos'
        },
        {
          title: '不合格项',
          align: 'center',
          dataIndex: 'description'
        },
        {
          title: '结论',
          align: 'center',
          dataIndex: 'isOK',
          customRender: function(text) {
            if (text) {
              return 'NOK'
            } else {
              return 'OK'
            }
          }
        }
      ],
      url: {
        list: '/trace/barcodeTrace/listMesStatusWordValueByMainId'
      },
      dictOptions: {}
    }
  },
  created() {
  },
  computed: {
    importExcelUrl() {
      return `${window._CONFIG['domianURL']}/${this.url.importUrl}/${this.mainId}`
    }
  },
  methods: {
    tableRowClass(record, index) {
      if (record.isOK) {
        return 'red'
      } else {
        return ''
      }
    },

    clearList() {
      this.dataSource = []
      this.selectedRowKeys = []
      this.ipagination.current = 1
    }

  }
}
</script>
<style scoped>
@import '~@assets/less/common.less';

</style>
<style>
.red {
  color: red;
}
</style>